<?php
/**
 * Created by PhpStorm.
 * User: ytlmi
 * Date: 2018/3/12
 * Time: 10:38
 */

namespace org\util\wordTool\example;

use function foo\func;
use org\util\wordTool\Table;
use org\util\forensicTool\ForensicCalculate;

class ReportTy extends WriteReport
{
    protected function addSampleTable()
    {
        $table = $this->body->addTable(self::TABLE_STYLE);
        $roleGroup = $this->makeRoleGroup();
        foreach ($roleGroup[1] as $role) {
            $this->addRow($table, $role);
        }
        foreach ($roleGroup[0] as $index => $role) {
            $position = $index == count($roleGroup[0]) - 1 ? 'last' : 'mid';
            $this->addRow($table, $role, $position);
        }
    }


    protected function addRow(Table $table, $role, $position = 'mid')
    {
        $positionMap = ['first' => self::FIRST_ROW_STYLE, 'mid' => self::MID_ROW_STYLE, 'last' => self::LAST_ROW_STYLE];
        $width = [4000, 4000];
        if ($role == 'head') {
            $content = ['检材描述', '样本编号'];
        } else {
            $content = [$this->caseData['samples'][$role]['person_name'], $this->caseData['samples'][$role]['sample_name']];
        }
        $table->addSimpleRow($content, $width, self::TABLE_FONT, $positionMap[$position]);
    }

    /**
     * @throws \Exception
     */
    protected function addDetectionTable()
    {
        $roleGroup = $this->makeRoleGroup();

        //设置单元格宽度
        $positionMap = ['first' => self::FIRST_ROW_STYLE, 'mid' => self::MID_ROW_STYLE, 'last' => self::LAST_ROW_STYLE];
        $width = 8000 / (count($roleGroup[1]) + 1);

        //每个亲代与每个子代生成对比表格
        $tableIndex = 0;
        foreach ($roleGroup[0] as $yz) {
            $tableIndex++;
            $arrMarker = [];//全部基因座
            $head = ['基因座'];//第一行
            $table = $this->body->addTable(self::TABLE_STYLE);
            foreach ($roleGroup[1] as $wz) {
                $arrMarker = array_merge($arrMarker, array_keys($this->caseData['samples'][$yz]['genotype']));
                $head[] = $this->caseData['samples'][$wz]['sample_name'];
            }
            $head[]=$this->caseData['samples'][$yz]['sample_name'];

            foreach ($arrMarker as $marker) {
                $content=[$marker];
                foreach ($roleGroup[1] as $wz) {
                    $content[]=$this->caseData['samples'][$wz]['genotype'][$marker];
                }
                $content[]=$this->caseData['samples'][$yz]['genotype'][$marker];
                $position = $marker == end($arrMarker) ? 'last' : 'mid';
                $table->addSimpleRow($content, $width, self::TABLE_FONT, $positionMap[$position]);
            }
        }
    }

}